package com.ruangong.GitClient.YanZhaoWang;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.List;
import com.ruangong.GitClient.R;

public class MajorAdapter extends ArrayAdapter<Major> {

    private Context context;
    private List<Major> majors;

    public MajorAdapter(Context context, List<Major> majors) {
        super(context, 0, majors);
        this.context = context;
        this.majors = majors;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View listItem = convertView;
        if (listItem == null) {
            listItem = LayoutInflater.from(context).inflate(R.layout.major_item, parent, false);
        }

        Major currentMajor = majors.get(position);

        TextView majorNameTextView = listItem.findViewById(R.id.majorNameTextView);
        majorNameTextView.setText(currentMajor.getMajor());

        return listItem;
    }
}
